package com.spoj;

import java.util.Arrays;
import java.util.Scanner;

public class SUPPER{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        for (int i = 0;i< 10; i++){
            int number = input.nextInt();
            input.nextLine();
            String data = input.nextLine();
            String[] dataArr = data.split(" ");
            int[] lis = new int[number];
            for(int j=0;j<lis.length;j++){
                lis[j] = 1;
            }
            for(int j=1;j<number;j++){
                for(int k=0;k<j;k++){
                    if(Integer.parseInt(dataArr[j]) > Integer.parseInt(dataArr[k]) && lis[j] < lis[k] + 1){
                        lis[j] = lis[k] + 1;
                    }
                }
            }
            StringBuffer sb = new StringBuffer();
            int count = 1;
            int outcount = 0;
            int result[] = new int[number];
            for(int j = 0;j < number;j++){
                if(count == lis[j]){
                    result[j] = Integer.parseInt(dataArr[j]);
                    outcount++;
                }else if(lis[j] > count){
                    count = lis[j];
                    result[j] = Integer.parseInt(dataArr[j]);
                    outcount++;
                }
            }
            Arrays.sort(result);
            for(int j=0;j<outcount;j++){
                sb.append(result[j + number-outcount] + " ");
            }
            System.out.println(outcount);
            System.out.println(sb.toString().substring(0, sb.toString().length()-1));
        }
        input.close();
    }
}